public class StressRead extends Thread {
	
	public static void main(String argv[]) throws InterruptedException{
		
		if (argv.length != 1) {
			System.out.println("java StressWrite <nb iteration>");
			return;
		}
		int nb = Integer.parseInt(argv[0]);
		
		// initialize the system
		Client.init();
		
		// look up the counter object in the name server
		// if not found, create it, and register it in the name server
		
		Counter_itf c = (Counter_itf) Client.lookup("Counter");
		
		if (c == null) {
			c = (Counter_itf) Client.create(new Counter());
			Client.register("Counter", c);
		}	
		
		sleep(470);
		System.out.println("Reader started");
		int j;
		
		for (int i=1; i<=nb; i++){
			
			c.lock_read();
			j = c.read();
			if(i%(nb/50) == 1)
				System.out.println("read " + j);
			c.unlock();

		
		}
		sleep(2500);
		System.out.println("Reader terminated");
	}
}